﻿using System.Collections.Concurrent;
using System.Collections.ObjectModel;

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            List<Person> testList = new List<Person>
            {
                new Person
                {
                    Id = 1,
                    Name = "张三",
                    City = "北京",
                    Sex = "男",
                },
                new Person
                {
                    Id = 2,
                    Name = "李四",
                    City = "上海",
                    Sex = "女",
                },
                new Person
                {
                    Id = 3,
                    Name = "王五",
                    City = "广州",
                    Sex = "男",
                },
                new Person
                {
                    Id = 4,
                    Name = "赵六",
                    City = "深圳",
                    Sex = "女",
                },
                new Person
                {
                    Id = 5,
                    Name = "孙七",
                    City = "杭州",
                    Sex = "男",
                },
            };

            //方法一：循环查找
            var ResultList = new List<Person>();
            foreach (var item in testList)
            {
                if (item.Sex == "男")
                {
                    ResultList.Add(item);
                }
            }
            //方法二: Linq语句
            var ResultList2 = from item in testList where item.Sex == "男" select item;

            //方法三：lambda
            var result3 = testList.Where(x => x.Sex == "男");

            Func<int, int> action = x => x + 1;
            Func<int, int> action2 = (x) => x + 1;

            Func<int, int, int> sum = (x, y) => x + y;

            Action<bool> action1 = (isOpen) =>
            {
                if (isOpen)
                {
                    Console.WriteLine("打开");
                }
                else
                {
                    Console.WriteLine("关闭");
                }
            };

            Action<int> action3 = _ =>
            {
                Console.WriteLine("执行了aciton");
            };

            Console.WriteLine(action(1));
            Console.WriteLine(action2(1));

            Console.ReadKey();

            List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
            var evenNumbers = numbers.Where(n => n % 2 == 0).ToList();
        }
    }

    class Person
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string City { get; set; }

        public string Sex { get; set; }
    }
}
